// pages/new_shop/new_shop.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    one_class:[],
    show_picker:true,
    shop_class:'选择商品分类(必填)',
    can_commit:false,
    good_name:false,
    contact:false
  },

  commit: function (e) {
    var that = this
      app.ajax({
          url: app.host + 'mall/User/demand',
          data: {
              good_name: e.detail.value.good_name,
              good_cate: that.data.shop_class,
              good_brand: e.detail.value.good_brand,
              good_spec: e.detail.value.shop_people,
              agent: e.detail.value.agent,
              price: e.detail.value.price,
              remark: e.detail.value.remark,
              contact: e.detail.value.contact
          },
          success: function (res) {
              wx.showToast({
                  title: res.data.msg,
                  icon: 'success',
                  duration: 1000
              })
              setTimeout(function () {
                wx.navigateBack()
              }, 1000)
          }
      });

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var one_class = []
    app.ajax({
      url:app.host + 'mall/user/cate',
      success:function(res){
        that.setData({
          one_class: res.data.data
        })
        console.log(that.data.one_class)
      }
    })
  },
  bindPickerChange:function(e){
    var one_class = this.data.one_class
    if (e.detail.value){
      this.setData({
        can_commit:true,
        shop_class: one_class[e.detail.value].cate_name
      })
    }
  },
  disabled:function(e){
    if (e.currentTarget.dataset.name == "good_name" && e.detail.value!=""){
      this.setData({
        good_name:true
      })
    }
    if (e.currentTarget.dataset.name == "good_name" && e.detail.value == ""){
      this.setData({
        good_name: false
      })
    }
    if (e.currentTarget.dataset.name == "contact" && e.detail.value != ""){
      this.setData({
        contact: true
      })
    }
    if (e.currentTarget.dataset.name == "contact" && e.detail.value == "") {
      this.setData({
        contact: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})